package com.netty.http;

import io.netty.channel.ChannelFutureListener;                                                                                  
import io.netty.channel.ChannelHandlerContext;                                                                                  
import io.netty.channel.SimpleChannelInboundHandler;                                                                            
import io.netty.handler.codec.http.DefaultFullHttpResponse;                                                                     
import io.netty.handler.codec.http.FullHttpResponse;                                                                            
import io.netty.handler.codec.http.HttpResponseStatus;                                                                          
import io.netty.handler.codec.http.HttpVersion;                                                                                 
                                                                                                                                
/**                                                                                                                             
 * A simple handler which will simple return a successful Http                                                                  
 * response for any request.                                                                                                    
 */                                                                                                                             
public class OkResponseHandler extends SimpleChannelInboundHandler<Object> {                                                    
    @Override                                                                                                                   
    public void channelRead0(ChannelHandlerContext ctx, Object msg) {                                                           
        final FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);             
        response.headers().set("custom-response-header", "Some value");                                                         
        ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);                                                   
    }                                                                                                                           
}                                                                                                                               

